-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dylan Reid - Pet Park Assignment #37
base: main
Are you sure you want to change the base?
Conversation
|
||
// define struct of animal type, age, and gender | ||
struct animalAndDemo { | ||
uint animalType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use enums for animal type and gender
address owner; | ||
|
||
// define struct of animal type, age, and gender | ||
struct animalAndDemo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general convention is to have the first letter as uppercase in names of structs, classes and events
emit Added(animalType, count); | ||
} | ||
|
||
function borrow(uint age, uint gender, uint animalType) public animalRange(animalType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be marked external since it is not being called anywhere internally
|
||
function add(uint animalType, uint count) public animalRange(animalType) { | ||
// check that only owner has access | ||
require(owner == msg.sender, "Not an owner"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to check this with a modifier as it make the code more readable
|
||
function animalCounts(uint animalType) public view returns(uint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since solidity public mappings are automatically exposed as functions, you can just make animalCounts
as a public mapping. Here you just have to rename animalsInZoo
to animalCounts
|
||
// set animal type back to zero in borrow mapping | ||
uint currentAge = borrowedAnimal[msg.sender].age; | ||
uint currentGender = borrowedAnimal[msg.sender].gender; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since borrowedAnimal[msg.sender]
is being used multiple times it can be stored in a single memory variable. Later in the course you will learn that it is a gas optimisation technique
uint gender; | ||
} | ||
|
||
// animals in zoo: animalType and count of that animal in the zoo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In solidity it is recommended to use Natspec format for commenting
No description provided.